

<div id="rbac_resource_save">
    <form>
        <zrow>

            <zcol :md="6">
                <zselect chosen="true" label="上级资源ID" name="pid" :ctx="this" :data="allRes" defaut="0,顶级资源"/>
            </zcol>

            <zcol :md="6">
                <zinput label="资源名称" name="name" :ctx="this"/>
            </zcol>
        </zrow>


        <zrow>
            <zcol :md="6">
                <zinput label="链接地址" name="link" :ctx="this"/>
            </zcol>

            <zcol :md="6">
                <zinput label="标识符" name="code" :ctx="this"/>
            </zcol>
        </zrow>


        <zrow>

            <zcol :md="6">
                <zradio label="类型" name="type" :ctx="this" :data='[{label:"菜单",value:0},{label:"按钮",value:1}]'/>
            </zcol>
        </zrow>

        <zrow>
            <zcol :md="6">
                <ztextarea label="URI" name="uris" :ctx="this" height="8em"/>
            </zcol>
        </zrow>

        <a @click="submit" class="btn btn-primary">提交</a>
    </form>

</div>

<script>
    new Vue({
        el:'#rbac_resource_save',
        mounted:function(){
            var _this = this ;
            if(this.editData){
                copyProperty(this.editData , this.form)
            }
            this.state.status = 'mounted'
            zhttp.get('rbac/resource/all').then(function (data) {
                _this.allRes = data.map(function (d) {
                    return {"label":d.name , "value":d.id}
                })
            })
            
            zhttp.get('rbac/resource/uri',{resource_id:App.url().param('id')}).then(function (data) {
                var uri = []
                data.map(function (d) {
                    var item = d.uri
                    if(d.method){
                        item += '@' + d.method
                    }
                    uri.push(item)
                })
                _this.form.uris = uri.join("\n")
            })
        },
        data:{
            state:{
                status:''
            },
            allRes:[],
            
            form:{
                pid:0,
                type:0,
                link:'',
                code:'',
                name:'',
                uris:'234234',
            },
            validate:{
                pid:[Va.required],
                type:[Va.required],
                code:[Va.required],
                name:[Va.required],
            },
            editData:{!! $data !!}
        },
        methods:{
            submit:function(){

                if(!validateAll(this)){
                    return
                }

                var id = App.url().param('id') || '' ;

                zhttp.post('rbac/Resource/save?id='+id,this.form,function (d) {
                    if(d.code == 0){
                        success('操作成功')
                        //Loader.getDialog('rbac/Resource/save').close()
                        go('rbac/Resource/index')
                    }else{

                    }
                    return false ;
                })
            }
        }
    })
</script>